/*
 *  Copyright 2011 yura.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */

package org.opu.vcforms.view.component;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.AbstractButton;

/**
 *
 * @author yura
 */
public class RolloverMouseListener extends MouseAdapter{
    //private final Object object = new Object(); //current version canceled synchronization

    /**
     *  Set some properties that needed set to button
     * before it`s will be ready to use. The properties
     * is: contentAreaFilled = false, and borderPainted =
     * false.
     * @param button button where properties will be changed
     */
    public void preInitButton(AbstractButton button){
        //synchronized(object){
        button.setContentAreaFilled(false);
        button.setBorderPainted(false);
        button.setFocusPainted(false);
        //}
    }

    /**
     *  Set some properties that dont needed button
     * after removed curent mouse listener. The properties
     * is: contentAreaFilled = true, and borderPainted =
     * true.
     * @param button button where properties will be changed
     */
    public void postInitButton(AbstractButton button){
        //synchronized(object){
        button.setContentAreaFilled(true);
        button.setBorderPainted(true);
        button.setFocusPainted(true);
        //}
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        //synchronized(object){
            Object source = e.getSource();
            if (source instanceof AbstractButton) {
                AbstractButton button = (AbstractButton) source;
                button.setContentAreaFilled(true);
                button.setBorderPainted(true);
            }
        //}
    }

    @Override
    public void mouseExited(MouseEvent e) {
        //synchronized(object){
            Object source = e.getSource();
            if (source instanceof AbstractButton) {
                AbstractButton button = (AbstractButton) source;
                button.setContentAreaFilled(false);
                button.setBorderPainted(false);
            }
        //}
    }
}
